
public class DuckSimulator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		DuckSimulator simulator = new DuckSimulator();
		AbstractDuckFactory factory	= new CountingDuckFactory();
		
		simulator.simulate(factory);
	}

	void simulate(AbstractDuckFactory factory) {
		Quackable redheadDuck = factory.createRedheadDuck();
		Quackable duckCall		= factory.createDuckCall();
		Quackable rubberDuck	= factory.createRubberDuck();
		Quackable gooseAdapter	= new GooseAdapter(new Goose());
		
		System.out.println("\nDuck Simulator: with Observer");
		
		Flock flock = new Flock();
		flock.add(redheadDuck);
		flock.add(duckCall);
		flock.add(rubberDuck);
		flock.add(gooseAdapter);
		
		Quackable mallard1 = factory.createMallardDuck();
		Quackable mallard2 = factory.createMallardDuck();
		Quackable mallard3 = factory.createMallardDuck();
		Quackable mallard4 = factory.createMallardDuck();
		Flock mallardFlock = new Flock();
		mallardFlock.add(mallard1);
		mallardFlock.add(mallard2);
		mallardFlock.add(mallard3);
		mallardFlock.add(mallard4);
		
		flock.add(mallardFlock);
		
		Quackologist quackologist = new Quackologist();
		flock.registerObserver(quackologist);
		simulate(flock);

		
		System.out.println("\n" + QuackCounter.getQuacks() + " quacks were counted");
	}
	
	void simulate(Quackable duck) {
		duck.quack();
	}
}
